import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'
import moment from 'moment'

let _this = null
class Column extends Opt {

  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  enclosure(name, value, type) {
    if (value) {
      return {
        btn: [{
          title: '有',
          event: 'onFile',
          data: { name, value, type }
        }]
      }
    } else {
      return {
        text: {},
        placeholder: '无'
      }
    }
  }

  createAll() {
    this.all = [
    {
      title: '公司',
      field: 'orgCompanyName',
      minWidth: 150,
      // tree: true
    },
    {
      title: '案场',
      field: 'housesName',
      minWidth: 150,
    },
    {
      title: '状态',
      field: 'statusDesc',
      minWidth: 120,
    },
    {
      title: '签约套数',
      field: 'contractQuantity',
      minWidth: 100,
    },
    {
      title: '签约面积(㎡)',
      field: 'contractArea',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约金额(元)',
      field: 'contractAmount',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '是否发送业绩确认',
      field: 'isSend',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.isSend.split('@').join('、')
          })
        }
      }
    },
    {
      title: '快递单号',
      field: 'courierNum',
      minWidth: 180,
      cell: {
        text: {
          show: true
        }
      }
    },
    {
      field: 'noSendExplain',
      title: '未发送说明',
      minWidth: 180,
      slots: {
        default: (params, h) => {
          let tipsHtml = ''
          let periodList = params.row.confirmDate!='' && params.row.confirmDate.split('@')

          params.row.noSendExplain!='' && params.row.noSendExplain.split('@').forEach((ele,index) => {
            let period =  moment(periodList[index].split(',')[0]).format('yyyy-MM-DD') +'至'+moment(periodList[index].split(',')[1]).format('yyyy-MM-DD')
            tipsHtml+=`<div style="padding-top:5px;"><p>周期：${period}</p><p style="padding-bottom:5px;border-bottom:${index==params.row.noSendExplain.split('@').length-1?'0px':'1px'} solid #e8eaec;">${ele}</p></div>`
          });

          return table.cell.text(h, {
            value:params.row.noSendExplain!=''? params.row.noSendExplain.split('@')[0]:'-',
            isHtml: true,
            tooltip:params.row.noSendExplain!=''?true:false,
            theme:'light',
            tipsHtml: tipsHtml
          })
        }
      }
    },
    {
      field: 'isConfirm',
      title: '甲方是否确认',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.isConfirm.split('@').join('、')
          })
        }
      }
    },
    {
      title: '原件-开发商公章',
      minWidth: 140,
      cell: (item) => {
        return this.enclosure('原件-开发商公章', item.officialSeal1, 1)
      }
    },
    {
      title: '原件-开发商除公章外其他章',
      minWidth: 200,
      cell: (item) => {
        return this.enclosure('原件-开发商除公章外其他章', item.officialSeal5, 5)
      }
    },
    {
      title: '原件-开发商人员签字',
      minWidth: 160,
      cell: (item) => {
        return this.enclosure('原件-开发商人员签字', item.officialSeal3, 3)
      }
    },
    {
      title: '复印件-开发商盖章',
      minWidth: 150,
      cell: (item) => {
        return this.enclosure('复印件-开发商盖章', item.officialSeal2, 2)
      }
    },
    {
      title: '复印件-开发商人员签字',
      minWidth: 180,
      cell: (item) => {
        return this.enclosure('复印件-开发商人员签字', item.officialSeal4, 4)
      }
    },
    {
      field: 'remarks',
      title: '备注',
      minWidth: 250,
      slots: {
        default: (params, h) => {
          let tipsHtml = ''
          let periodList = params.row.confirmDate!='' && params.row.confirmDate.split('@')

          params.row.remarks!='' && params.row.remarks.split('@').forEach((ele,index) => {
            let period =  moment(periodList[index].split(',')[0]).format('yyyy-MM-DD') +'至'+moment(periodList[index].split(',')[1]).format('yyyy-MM-DD')
            tipsHtml+=`<div style="padding-top:5px;"><p>周期：${period}</p><p style="padding-bottom:5px;border-bottom:${index==params.row.remarks.split('@').length-1?'0px':'1px'} solid #e8eaec;">${ele}</p></div>`
          });

          return table.cell.text(h, {
            value:params.row.remarks!=''? params.row.remarks.split('@')[0]:'-',
            isHtml: true,
            tooltip:params.row.remarks!=''?true:false,
            theme:'light',
            tipsHtml: tipsHtml
          })
        }
      }
    },{
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      cell: (item) => {
        return {
          btn: [{
            title: '查看明细',
            event: 'linkDetailFun',
            data: item.housesId
          }]
        }
      }
    }]
  }

}

export default Column